//
//  PKPlayInfoViewController.m
//  PianKe
//
//  Created by lanou on 15/10/7.
//  Copyright (c) 2015年 李伟伟. All rights reserved.
//

#import "PKPlayInfoViewController.h"
#import "PKRequestManager.h"
#import "PKRadioPlayInfoModel.h"
#import "PKPlayInfoView.h"
@interface PKPlayInfoViewController ()
@property(nonatomic,strong)PKRadioPlayInfoModel *playInfoModel;
@property(nonatomic,strong)PKPlayInfoView *playInfoView;
@end
@implementation PKPlayInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.configureModel = _dataSourceArray[_index];
    [self setConfigureModel:_configureModel];
    
}


-(void)setConfigureModel:(PKRadioDetailModel *)configureModel
{
    _configureModel = configureModel;
    self.tingid = _configureModel.tingid;
    [self requestData];
}

-(void)requestData
{
        
    NSMutableDictionary *pardic = [NSMutableDictionary dictionary];
    pardic[@"auth"] = @"";
    pardic[@"client"] = @"1";
    pardic[@"deviceid"] = @"63A94D37-33F9-40FF-9EBB-481182338873";
    pardic[@"tingid"] = _tingid;
    pardic[@"version"] = @"3.0.4";
    
    [PKRequestManager requestWithType:POST urlString:@"http://api2.pianke.me/ting/info" parDic:pardic finish:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
       
            _playInfoModel = [[PKRadioPlayInfoModel alloc]init];
            [_playInfoModel setValuesForKeysWithDictionary:dic[@"data"]];

        
        _imageArray = [NSMutableArray arrayWithCapacity:0];
        for (NSDictionary *imagedic in _playInfoModel.moreting) {
            [_imageArray addObject:imagedic[@"coverimg"]];
        }
        
       
        _playInfoView = [[[UINib nibWithNibName:@"PKRadioPlayInfoView" bundle:nil] instantiateWithOwner:self options:nil] firstObject];
        _playInfoView.imageArray = _imageArray;

        _playInfoView.frame = CGRectMake(0, 0 , SCREEN_WITDTH , SCREEN_HEIGHT - 140);
        [self.view addSubview:_playInfoView];
        
              
        [_playInfoView configurePlayInfoData:self.configureModel];

              
        
        NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:_playInfoModel.like,@"like",_playInfoModel.comment,@"comment", nil];
        [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"configureNumber" object:nil userInfo:dictionary]];
        
        
        
    } error:^(NSError *error) {
        NSLog(@"===========");
    }];
 }





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
